package com.liyou.process.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.liyou.model.process.ProcessTemplate;
import com.liyou.model.process.ProcessType;
import com.liyou.process.service.OaProcessTemplateService;
import com.liyou.process.service.OaProcessTypeService;
import com.liyou.process.mapper.OaProcessTypeMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author asus
* @description 针对表【oa_process_type(审批类型)】的数据库操作Service实现
* @createDate 2023-06-09 17:00:31
*/
@Service
public class OaProcessTypeServiceImpl extends ServiceImpl<OaProcessTypeMapper, ProcessType>
    implements OaProcessTypeService{

    @Resource
    private OaProcessTemplateService oaProcessTemplateService;

    @Override
    public List<ProcessType> findProcessType() {
        //1 查询所有审批分类，返回list集合
        List<ProcessType> processTypeList = baseMapper.selectList(null);

        //2 遍历返回的所有审批分类集合
        for (ProcessType processType : processTypeList) {
            //3 得到每个审批分类，根据审批分类id查询对应审批模板
            Long id = processType.getId();
            LambdaQueryWrapper<ProcessTemplate> wrapper = new LambdaQueryWrapper<>();
            wrapper.eq(ProcessTemplate::getProcessTypeId, id);
            List<ProcessTemplate> processTemplateList = oaProcessTemplateService.list(wrapper);

            //4 将审批模板数据封装到每个审批分类对象里面
            processType.setProcessTemplateList(processTemplateList);
        }

        return processTypeList;
    }
}




